package com.ims.controller.system.course;

import com.ims.controller.base.BaseController;
import com.ims.entity.system.Course;
import com.ims.entity.system.Grade;
import com.ims.service.CourseService;
import com.ims.service.GradeService;
import com.ims.shiro.ShiroSessionService;
import com.ims.util.PageData;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping(value = "/course")
public class CourseController extends BaseController{
    @Resource
    private CourseService courseService;
    @Resource
    private GradeService gradeService;
    @Resource
    ShiroSessionService session;

    //选课课表
    @RequestMapping("/selectclass")
    public ModelAndView selectclass() throws Exception{
        ModelAndView mv = this.getModelAndView();
        List<Course> courseList=courseService.listAllCourse();
        mv.addObject("courseList",courseList);
        mv.setViewName("system/course/selectclass");
        return  mv;
    }

    //添加课程
    @RequestMapping(value = "/addClass")
    public ModelAndView addClass(Course course) throws  Exception{
        ModelAndView mv = this.getModelAndView();
        PageData pd=new PageData();
        pd=this.getPageData();

        course.setCno(Integer.parseInt( pd.getString("cno")));
        course.setCname(pd.getString("cname"));
        course.setCattribute(pd.getString("cattribute"));
        courseService.saveCourse(course);

        mv.addObject("msg","success");
        mv.setViewName("system/course/addclass");
        return mv;


    }

    //选课
    @RequestMapping(value = "/checkClass")
    public ModelAndView checkClass()throws Exception{
        ModelAndView mv=this.getModelAndView();
        PageData pd=new PageData();
        pd=this.getPageData();
        String uname=session.getSession().getAttribute("USERNAME").toString();
        Integer cno=Integer.parseInt( pd.getString("cno"));
        Grade grade=new Grade();
        grade.setUname(uname);
        grade.setCno(cno);
        grade.setGrade(0);
        gradeService.addCourse(grade);

        mv.addObject("msg","success");
        mv.setViewName("system/course/selectclass");
        return mv;




    }




}
